package com.ttctracker.search;

import java.util.ArrayList;

import com.ttctracker.classes.StopItem;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class StopArrayAdapter extends ArrayAdapter<StopItem>{

	private ArrayList<StopItem> stopItems;
	
	public StopArrayAdapter(Context context, int textViewResourceId,
			ArrayList<StopItem> objects) {
		super(context, textViewResourceId, objects);
		stopItems=objects;
		
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View v = convertView;
		if (v == null) {
			LayoutInflater vi = (LayoutInflater) getContext().getSystemService(
					Context.LAYOUT_INFLATER_SERVICE);
			v = vi.inflate(com.ttctracker.R.layout.view_stop_item, null);
		}
		
		StopItem stopItem=stopItems.get(position);
		if (stopItem!=null) {
			String title=stopItem.get_title();
			
			TextView stopTextView1=(TextView)v.findViewById(com.ttctracker.R.id.view_search_stop_title);
			TextView stopTextView2=(TextView)v.findViewById(com.ttctracker.R.id.view_search_stop_sub);
			
			String[] title_splitStrings=title.split("At");
					
			if (title_splitStrings.length>1) {
				stopTextView1.setText(title_splitStrings[1]);
				stopTextView2.setText("@ "+title_splitStrings[0]);
				stopTextView2.setVisibility(View.VISIBLE);
			}else {
				stopTextView1.setText(title_splitStrings[0]);
				stopTextView2.setVisibility(View.GONE);
			}
			
		}
		return v;
	}

}
